local RSNG = RSNG
local AceOO = AceLibrary("AceOO-2.0")
local C = RSNG.Classes

local StatusBar = AceOO.Class(C.IUIElement)

function StatusBar.prototype:init()
	StatusBar.prototype.parent.init(self)
end

function StatusBar.prototype:SetInfo(info)
	if info then
		assert(AceOO.inherits(info, C.IStatusBarInfo))
	end
	if self.info ~= info then
		self.info = info
		if info and AceOO.inherits(info, C.ITooltipInfo) then
			if not self.tooltip then
				self.tooltip = RSNG.Pools.Tooltip:New()
			end
			self.tooltip:SetInfo(info)
		else
			if self.tooltip then
				RSNG.Pools.Tooltip:Release(self.tooltip)
				self.tooltip = nil
			end
		end
	end
end

function StatusBar.prototype:Update()
	local info = self.info
	if not info then return end
	local f = self:GetFrame()
	f.left:SetText(info:GetText())
	local min, max, count = info:GetCount()
	f.status:SetRange(min, max)
	f.status:SetPos(count)
	f.status:SetColor(info:GetColor())
	f.right:SetText(info:GetTextFormat()(min, max, count))
end

C.StatusBar = StatusBar
